<?php

namespace app\index\validate;

use think\captcha\Captcha;
use think\Validate;
use app\common\library\Sms;

class User extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'ip|ip地址'=>'ip',
        'platform|来源平台'=>'require',
        'tel|手机号码'=>'require|regex:^1\d{10}',
        'username|用户名'=>'require',
        'qq'=>'require|number',
        'weixin|微信'=>'require',
        'age|年龄'=>'require|number',
        'zhimafen|芝麻分'=>'require|number',
        'tpyzm|图片验证码'=>'require|captcha',
        'dxyzm|短信验证码'=>'require|checksms:thinkphp',
        'belong_id|所属用户'=>'require',
        '__token__' => 'token',

    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'regist1'  => ['ip','tel','tpyzm','dxyzm','__token__'],
        'regist2'  => ['username','qq','weixin','zhimafen','tel','tpyzm'=>'checkreg3:thinkphp','dxyzm','__token__'],
        'regist3'  => ['username','qq','zhimafen','tel','__token__'],
        'user'  => ['username','qq','weixin','age','zhimafen','__token__'],

    ];

    public function checksms($value,$rule,$data){

        if (!Sms::check($data['tel'], $value, 'register'))
        {
            return '验证码不正确';
        }else{
            return true;
        }
    }

    public function checkreg3($value,$rule,$data){
        $captcha = new Captcha();
        return $captcha->check($value, '10');
    }
}
